package com.zztl.infiniteBand.ui.activity

import android.view.Gravity
import android.view.KeyEvent
import android.view.View
import android.view.ViewGroup
import com.tencent.bugly.beta.Beta
import com.tencent.bugly.beta.download.DownloadTask
import com.zztl.infiniteBand.R
import com.zztl.infiniteBand.base.BaseActivity
import com.zztl.infiniteBand.util.LogUtils
import kotlinx.android.synthetic.main.activity_upgrade.*

class UpgradeActivity : BaseActivity() {
    override fun setLayoutId(): Int = R.layout.activity_upgrade

    override fun initBase() {
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        window.setGravity(Gravity.CENTER)
        LogUtils.d("swl","-----"+Beta.getUpgradeInfo().updateType+"    "+Beta.getUpgradeInfo().upgradeType)
        if(Beta.getUpgradeInfo().upgradeType==1){
            btn_cancel.visibility=View.VISIBLE
        }else{
            btn_cancel.visibility=View.GONE
        }
        upgrade_content.text= Beta.getUpgradeInfo().newFeature
        btn_cancel.setOnClickListener {
            Beta.cancelDownload()
            finish() }

        btn_confirm.setOnClickListener {
            Beta.startDownload()?.run {
                if(status==DownloadTask.DOWNLOADING){
                    finish()
                }
            }
        }


    }


    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(keyCode==KeyEvent.KEYCODE_BACK){
            if(Beta.getUpgradeInfo().upgradeType==2){
                return true
            }
        }
        return super.onKeyDown(keyCode, event)
    }

}
